package com.direct.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	private static SimpleDateFormat sdf = new SimpleDateFormat();
	
	public static Date parse(String source, String pattern) {
		if(source == null || source.trim().length() == 0) {return null;}
		
		sdf.applyPattern(pattern);
		
		try {
			return sdf.parse(source);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static String format(Date source, String pattern) {
		if(source == null) {return null;}
		
		sdf.applyPattern(pattern);
		return sdf.format(source);
	}
	
	public static Date getToday() {
		Date now = new Date();
		return parse(format(now, "yyyy-MM-dd"), "yyyy-MM-dd");
	}
}
